//
//  ZWHTeaDetailViewController.swift
//  约麻
//
//  Created by Syrena on 2017/7/19.
//  Copyright © 2017年 Sweet. All rights reserved.
//

import UIKit

class ZWHTeaDetailViewController: UIViewController {
    
    var opid:String?
    var name:String?
    var poiurl:String?
    var searchPOI=BMKPoiSearch()
    
    @IBOutlet weak var webview: UIWebView!
    
    override func viewWillAppear(_ animated: Bool) {
        navigationController?.isNavigationBarHidden = false
        searchPOI.delegate = self
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        searchPOI.delegate = nil
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setnavigation()
        search()
    }

    //设置导航栏
    func setnavigation(){
        
        navigationItem.title = name
        navigationController?.navigationBar.barTintColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
        //定义标题颜色与字体大小字典
        let dict:NSDictionary = [NSForegroundColorAttributeName: #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1),NSFontAttributeName : UIFont.boldSystemFont(ofSize: 13)]
        //标题设置颜色与字体大小
        
        navigationController?.navigationBar.titleTextAttributes = dict as? [String : AnyObject]
        
        let Btn = UIButton(frame: CGRect(x: 0, y: 0, width: 15, height: 15))
        Btn.setImage(UIImage.init(named:"黑色返回"), for: .normal)
        Btn.addTarget(self, action: #selector(backClicked), for: .touchUpInside)
        let back = UIBarButtonItem(customView: Btn)
        navigationItem.leftBarButtonItem = back
        
        
    }
    
    func backClicked(){
        navigationController?.popViewController(animated: true)
    }
    
    func search(){
                            let op = BMKPoiDetailSearchOption()
                            op.poiUid = opid
        searchPOI.poiDetailSearch(op)
    }
    

}

extension ZWHTeaDetailViewController:BMKPoiSearchDelegate{
    func onGetPoiDetailResult(_ searcher: BMKPoiSearch!, result poiDetailResult: BMKPoiDetailResult!, errorCode: BMKSearchErrorCode) {
        if errorCode == BMK_SEARCH_NO_ERROR{
            webview.loadRequest(URLRequest(url: URL(string: poiDetailResult.detailUrl)!))
        }
    }
}
